BASE_PATH=/home/chess
SHELL_PATH=$(cd `dirname $0`; pwd)
#创建docker容器互联网络
NETWORK_NAME=docker-net
docker network create -d bridge $NETWORK_NAME

#安装MySQL
rm -rf $BASE_PATH/mysql
mkdir -p $BASE_PATH/mysql/{conf,data}
docker container stop mysql
docker container rm mysql
docker run --name mysql \
           --network $NETWORK_NAME \
           -d \
           -p 3366:3306 \
           -e TZ="Asia/Shanghai" \
           -v /etc/localtime:/etc/localtime:ro \
           -v $BASE_PATH/mysql/conf:/etc/mysql/conf.d \
           -v $BASE_PATH/mysql/data:/var/lib/mysql \
           -e MYSQL_ROOT_PASSWORD="root" \
           mysql:5.7 \
           --character-set-server=utf8mb4 --collation-server=utf8mb4_bin

#安装Redis
rm -rf $BASE_PATH/redis
mkdir -p $BASE_PATH/redis/data
docker container stop redis
docker container rm redis
docker run --name redis \
           --network $NETWORK_NAME \
           -d \
           -e TZ="Asia/Shanghai" \
           -v /etc/localtime:/etc/localtime:ro \
           -v $BASE_PATH/redis/data:/data \
           redis \
           redis-server \
             --appendonly yes \
             --requirepass "this!IS_Redis_P@SSW0RD!@#$%^&*(0),./;"

#处理项目发布脚本
\cp -rf $SHELL_PATH/../publish*.sh $BASE_PATH/
\cp -rf $SHELL_PATH/publish*.sh $BASE_PATH/
chmod u+x $BASE_PATH/publish*.sh
#发布项目
$BASE_PATH/publish.sh

#创建nginx相关目录
mkdir -p $BASE_PATH/nginx/{conf,html,logs/webapp,logs/admin}
chmod -R 777 $BASE_PATH/nginx/logs

#发布后台静态资源
$BASE_PATH/publish-admin-ui.sh

#安装Nginx
rm -rf $BASE_PATH/nginx
\cp -rf $SHELL_PATH/nginx $BASE_PATH/nginx
docker container stop nginx
docker container rm nginx
#-v xxx:ro中的:ro表示挂载为只读
docker run --name nginx \
           --network $NETWORK_NAME \
           -d \
           -p 80:80 \
           -e TZ="Asia/Shanghai" \
           -v /etc/localtime:/etc/localtime:ro \
           -v $BASE_PATH/nginx/conf/conf.d:/etc/nginx/conf.d:ro \
           -v $BASE_PATH/nginx/html:/etc/nginx/html:ro \
           -v $BASE_PATH/nginx/logs:/var/log/nginx \
           nginx

#发布微信个人号机器人
yum install -y nodejs
$BASE_PATH/publish-wechatbot.sh
